package com.example.mybatisdemo.demos.web.mapper;
import com.example.mybatisdemo.demos.web.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Q
 * @create 2025-06-06-9:32
 */
@Mapper
public interface UserInfoMapper {
    @Select("select * from userinfo")
    List<UserInfo> queryUserInfos();

    @Select("select * from userinfo where id = ${value}")
    UserInfo queryUserInfo(Integer id);

    @Select("select * from userinfo where username = '${username}'")
    UserInfo queryUserInfoByName(String username);

    @Select("select * from userinfo where id = #{param1} and username= #{param2}")
    UserInfo queryUserInfoByIdAndName(Integer id, String name);

    @Select("select * from userinfo where id = #{id} and username= #{param2}")
    UserInfo queryUserInfoByIdAndName2(@Param("id") Integer id, @Param("name") String name);
    //插入数据（对象）
    @Insert("insert into userinfo (username, `password`, age, gender, phone, delete_flag)" +
            " values(#{username},#{password},#{age},#{gender},#{phone}, #{deleteFlag})")
    Integer insert(UserInfo userInfo);
    //插入数据
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo (username, `password`, age, gender, phone, delete_flag)" +
            " values(#{userInfo.username},#{userInfo.password}," +
            "#{userInfo.age},#{userInfo.gender},#{userInfo.phone}, #{userInfo.deleteFlag})")
    Integer insert2(@Param("userInfo") UserInfo userInfo);
    //删除数据
    @Delete("delete from userinfo where id = #{id}")
    Integer delete(int id);
    //修改数据
    @Update("update userinfo set username=#{username} where id=#{id}")
    Integer update(UserInfo userInfo);
    //查询数据
    //1.起别名
    @Select("select id, username, password, age, gender, phone, " +
            "delete_flag as deleteFlag, create_time as createTime, update_time as updateTime" +
            "  from userinfo")
    List<UserInfo> queryUserInfos2();
    //结果映射
    @Select("select * from userinfo")
    List<UserInfo> queryUserInfos3();
    //配置yml
    @Select("select * from userinfo")
    List<UserInfo> queryUserInfos4();
}
